from django.db import models
from utils.basemodel import BaseModel
# Create your models here.
class BrandModel(BaseModel):
    bname = models.CharField(max_length=50, verbose_name="品牌名称")
    logo = models.ImageField(upload_to="brand", verbose_name="品牌logo")
    class Meta:
        db_table = "df_brand"
    def __str__(self):
        return self.bname
class  CategoryModel(BaseModel):
    cname = models.CharField(max_length=50, verbose_name="分类名称")
    parent= models.ForeignKey("self", null=True, blank=True, on_delete=models.CASCADE,verbose_name="父级分类", related_name="children")
    ishot = models.BooleanField(default=False, verbose_name="是否热门")
    ishome = models.BooleanField(default=False, verbose_name="是否展示在首页")
    isgood= models.BooleanField(default=False, verbose_name="是否推荐")
    class Meta:
        db_table = "fgcategory"
    def __str__(self):
        return self.cname

class TeacherModel(BaseModel):
    tname = models.CharField(max_length=50, verbose_name="教师名称")
    job=models.CharField(max_length=50, verbose_name="职位")
    intro=models.TextField(verbose_name="简介")
    headimg=models.ImageField(upload_to="uploads", verbose_name="头像")
    class Meta:
        db_table = "fgteacher"
    def __str__(self):
        return self.tname

class CourseModel(BaseModel):
    cname= models.CharField(max_length=50, verbose_name="课程名称")
    category=models.ForeignKey(CategoryModel, on_delete=models.CASCADE, verbose_name="课程分类")
    teacher=models.ForeignKey(TeacherModel, on_delete=models.CASCADE, verbose_name="授课教师")
    cover=models.ImageField(upload_to="uploads", verbose_name="封面")
    level=models.IntegerField(choices=(('1', '初级'), ('2', '中级'), ('3', '高级')), verbose_name="难度等级",default=1)
    vedio=models.CharField(max_length=200, verbose_name="视频")
    price=models.DecimalField(max_digits=5, decimal_places=2, verbose_name="价格")
    discount=models.DecimalField(max_digits=5, decimal_places=2, verbose_name="折扣价格")
    ishome=models.BooleanField(default=False, verbose_name="是否推荐")
    ishot=models.BooleanField(default=False, verbose_name="是否热门")
    read=models.IntegerField(default=0, verbose_name="阅读量")
    content=models.TextField(verbose_name="课程内容",default="暂无")
    class Meta:
        db_table = "fgcourse"
    def __str__(self):
        return self.cname
